﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GiaPhuc.Data;
using System.Data;
using System.Web.Configuration;

namespace GiaPhuc
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        private string Keyword { get { return Request["keyword"] ?? String.Empty; } }

        public IList<EZPages> Guides
        {
            get { return Session["Guide"] as IList<EZPages>; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Keyword != String.Empty)
                {
                    this.txtSearchBox.Text = Keyword;
                }

                if (null == Session["InfoNews"])
                {
                    Session["InfoNews"] = RssManager.ReadFeed(WebConfigurationManager.AppSettings["rss"]).Take(8).ToList();
                }

                using (IDbConnection connection = new MySql.Data.MySqlClient.MySqlConnection(Helper.ConnectionString))
                {
                    using (ResellEraDMInPhUkIeNipAdX context = new ResellEraDMInPhUkIeNipAdX(connection))
                    {
                        Session["Guide"] = context.EZPages.Where(x => x.ToCChapter == (int)PageType.Guide).OrderBy(x => x.PagesTitle).ToList();
                    }
                }

                this.SiteMapPath1.Visible = (SiteMap.CurrentNode != SiteMap.RootNode);
            }
        }
    }
}
